package com.example.room.user

import androidx.room.*
import com.example.room.user.User

@Dao
interface UserDao {
    // 查询
    @Query("SELECT * FROM USER")
    fun queryAllUser(): MutableList<User>

    //根据姓名参数查询
    @Query("SELECT * FROM USER WHERE id = :id")
    fun queryFindUser(id: Int): User?

    @Query("SELECT * FROM USER WHERE account = :name")
    fun queryFindUserByName(name: String): User?

    @Query("SELECT * FROM USER ORDER BY id DESC LIMIT 1")
    fun queryUserMax(): User?

    // 添加单条数据
    @Insert
    fun addUser(vararg user: User)

    // 添加批量数据
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addBatchUser(list: MutableList<User>)

    // 更新某一个数据
    @Update
    fun updateUser(vararg user: User)

    //删除某一个数据
    @Delete
    fun deleteSingle(vararg user: User)

    //删除表里所有数据
    @Query("DELETE FROM USER")
    fun deleteAllUser()
}